package com.qxzn.app.page.activity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.qxzn.app.page.BaseActivity;
import com.qxzn.app.page.R;
import com.qxzn.app.page.R2;
import com.qxzn.app.util.SharePreferenceUtil;

import butterknife.BindView;

public class SplashActivity extends BaseActivity {

    @BindView(R2.id.iv_splash)
    ImageView ivSplash;
    private CountDownTimer timer;

    @Override
    protected int initLayout() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void iniTitleBar() {
        title_bar.setVisibility(View.GONE);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        startCountTimeDown();
    }

    @Override
    protected void setFullScreen() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    private void startCountTimeDown() {
//        SharePreferenceUtil.setFirstStart(SplashActivity.this, true);
        timer = new CountDownTimer(1000, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {
                if (SharePreferenceUtil.isFirstStart(SplashActivity.this)) {
                    startActivity(new Intent(SplashActivity.this, GuideActivity.class));
                } else {
                    startActivity(new Intent().setComponent(new ComponentName(SplashActivity.this, "com.qxzn.app.personalcenter.activity.LoginByPwdActivity")));
                }
                finish();
            }
        };
        timer.start();
    }

    @Override
    protected void onDestroy() {
        if (timer != null) {
            timer.cancel();
        }
        super.onDestroy();
    }
}
